package com.scalar.chiptrack.finance.proformainvoice.actions;

import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.finance.proformainvoice.actioncommands.ProformaInvoiceActionCommandFactory;
import com.scalar.chiptrack.actioncommands.ActionCommand;
import com.scalar.chiptrack.commons.Constants;
import com.scalar.chiptrack.commons.SessionKeys;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * User: KP
 * Date: Sep 28, 2006
 * Time: 3:08:44 PM
 */
public class ProformaInvoiceAction extends ChipTrackAction implements Constants
{
    public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
    {

        ActionForward actionForward = mapping.findForward ( "success" );
        String action   = request.getParameter ( "action" );
        HashMap errors  = new HashMap();
        HashMap info    = new HashMap();

        request.setAttribute( SessionKeys.INFO_MESSAGES, info );
        request.setAttribute( SessionKeys.ERROR_MESSAGES, errors );
        try
        {
            if ( action == null )
            {
                action = ACTION_SEARCH_RELEASES ;
            }

            ActionCommand actionCommand = ProformaInvoiceActionCommandFactory.getActionCommand( action );

            if ( actionCommand != null )
            {
                //System.out.println("-------------1 ProformaInvoiceAction.execute --actionCommand = " + actionCommand.toString() );
                actionForward = actionCommand.execute( mapping, form, request, response );
                //System.out.println("-------------2 ProformaInvoiceAction.execute --actionForward = " + actionForward.toString() );
            }
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }

        return actionForward;
    }
}
